import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/model/medicine_advice_model.dart';

import '../../net/response/medicine_advice/medicine_lack_list_data.dart';

class MedicineLackListViewModel
    extends BaseListViewModel<MedicineLackListData> {
  MedicineLackListViewModel(super.context);

  ///长者姓名
  String? searchName;

  ///房间号
  String? roomName;

  ///药品名称
  String? medicineName;

  ///缺药登记日期
  String? lackDate;

  ///是否缺药
  PickerDataWithIdModel? lackStatus;

  var model = MedicineAdviceModel();

  @override
  Future<List<MedicineLackListData>> requestListData() async {
    return model.medicineLackList(
        customerNameLike: searchName,
        bedNoLike: roomName,
        drugNameLike: medicineName,
        lackDateLike: lackDate,
        status: lackStatus?.pickId,
        page: page,
        rows: pageLength);
  }

  @override
  void onCreated() {
    super.onCreated();
    requestRefresh();
  }

  var format = ['yyyy', '-', 'mm', '-', 'dd'];

  void chooseLackDate() {
    DatePicker.showDatePicker(context, currentTime: lackDate?.toDate(),
        onConfirm: (date) {
      lackDate = date!.toDateStr(format);
      notifyListeners();
      requestRefresh();
    });
  }

  void chooseLackStatus() {
    var items = [
      PickerDataWithIdModel(pickId: '1', pickName: '是'),
      PickerDataWithIdModel(pickId: '0', pickName: '否'),
    ];

    DataPickerView(context, items, currentFirstData: lackStatus,
        onSubmitListener: (p1, p2, p3) {
      lackStatus = items[p1];
      notifyListeners();
      requestRefresh();
    }).show();
  }

  void resetClick() {
    searchName = null;
    medicineName = null;
    lackDate = null;
    lackStatus = null;
    roomName = null;
    notifyListeners();
    requestRefresh();
  }
}
